package com.sbp.message.schedule;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dap.utils.SpringUtils;
import com.sbp.message.service.ConsumerMessageRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;

import java.util.Date;

/**
 * Created by wangmin on 2018/4/28.
 */
public class HistoryConsumerRecordCheckSchedule implements SimpleJob, InitializingBean {
    private static final Logger logger = LoggerFactory.getLogger(HistoryConsumerRecordCheckSchedule.class);

    private ConsumerMessageRecordService consumerMessageRecordService;
    @Override
    public void afterPropertiesSet() throws Exception {
        consumerMessageRecordService = SpringUtils.getBean(ConsumerMessageRecordService.class);
    }


    @Override
    public void execute(ShardingContext shardingContext) {
        final long day180Millis = 180 * 24*3600*1000L;
        Date date = new Date(System.currentTimeMillis() - day180Millis);
        int deleteRowCount = consumerMessageRecordService.deleteRecordBeforeTime(date);
        logger.info("delete {} row before {}", deleteRowCount, date.toString());
    }

}
